using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintScenesPerTag
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintScenesPerTag(clsProject cProject)
		{
			//Discarded unreachable code: IL_02d2, IL_02e9, IL_02f4, IL_0304, IL_03de, IL_03e0, IL_03f4, IL_0416
			int num = default(int);
			int num4 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				clsCollection<string> clsCollection = cProject.SceneTags(WithUnused: false);
				num2 = 3;
				if (clsCollection.Count() == 0)
				{
					num2 = 4;
					clsShared.cLang.TransMsgBox("This report only works if you enter one or more tags on your scenes. (Scene Editor, Details tab.)");
				}
				else
				{
					num2 = 6;
					frmPickTags frmPickTags = new frmPickTags(clsCollection);
					num2 = 7;
					frmPickTags.ShowDialog();
					num2 = 8;
					if (frmPickTags.colPickedTags.Count() != 0)
					{
						num2 = 10;
						clsCollection = frmPickTags.colPickedTags;
						num2 = 11;
						clsShared.cSubs.BusyMouse();
						num2 = 12;
						clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Scenes per Tag");
						num2 = 13;
						clsReport.AddTitle();
						num2 = 14;
						clsReport.AddCentered(cProject.Title + " by " + cProject.AuthorName);
						num2 = 15;
						clsReport.AddBR(2);
						num2 = 16;
						clsReport.SetTableBorder(1);
						num2 = 17;
						clsReport.OpenTable("cellpadding=5");
						num2 = 18;
						clsCollection<int> clsCollection2 = cProject.SceneIDsInOrder(WithUnused: false);
						num2 = 19;
						IEnumerator enumerator = clsCollection.GetEnumerator();
						while (enumerator.MoveNext())
						{
							string text = Conversions.ToString(enumerator.Current);
							num2 = 20;
							int num3 = 0;
							num2 = 21;
							clsReport.OpenRow();
							num2 = 22;
							clsReport.AddCell(clsReport.Bold(text), "colspan=2 align=left");
							num2 = 23;
							clsReport.CloseRow();
							num2 = 24;
							clsCollection2 = cProject.SceneIDsInOrder(WithUnused: false);
							num2 = 25;
							IEnumerator enumerator2 = clsCollection2.GetEnumerator();
							while (enumerator2.MoveNext())
							{
								int iD = Conversions.ToInteger(enumerator2.Current);
								num2 = 26;
								clsScene clsScene = cProject.get_SceneByID(iD);
								num2 = 27;
								clsChapter clsChapter = cProject.get_ChapterByID(clsScene.BelongsToChID);
								num2 = 28;
								if (clsScene.PassesTagFilter(text))
								{
									num2 = 29;
									num3++;
									num2 = 30;
									clsReport.OpenRow();
									num2 = 31;
									clsReport.AddCell("(" + clsChapter.ShortTitle() + ")");
									num2 = 32;
									clsReport.AddCell(clsScene.Title);
									num2 = 33;
									clsReport.CloseRow();
								}
								num2 = 34;
							}
							num2 = 35;
							if (enumerator2 is IDisposable)
							{
								(enumerator2 as IDisposable).Dispose();
							}
							num2 = 36;
							if (num3 == 0)
							{
								num2 = 37;
								clsReport.OpenRow();
								num2 = 38;
								clsReport.AddCell("");
								num2 = 39;
								clsReport.AddCell("No scenes with this tag");
								num2 = 40;
								clsReport.CloseRow();
							}
							num2 = 41;
						}
						num2 = 42;
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
						num2 = 43;
						clsReport.CloseTable();
						num2 = 44;
						clsReport.AddFooter(App.Title);
						num2 = 45;
						clsReport.Show();
						num2 = 46;
						PrintProgressEvent?.Invoke("Printing Complete");
						num2 = 47;
						clsShared.cSubs.NormalMouse();
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num4 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0414: Could not find block for branch target IL_03e0*/;
			}
			if (num4 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
